<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>layui</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/static/admin/lib/layui-v2.5.5/css/layui.css" media="all">
    <link rel="stylesheet" href="/static/admin/css/public.css" media="all">
    <style>
        .layui-table-cell{
            height:50px;
            line-height: 50px;
        }
    </style>
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">

        <fieldset class="table-search-fieldset" style="background-color: #F2F2F2;">
            <legend style="color: #00a2d4;">面单发放记录</legend>
            <div style="margin: 10px 10px 10px 10px;">

                <div class="layui-card">
                    <div class="layui-card-header">面单记录说明</div>
                    <div class="layui-card-body">
                        与实际纸质快递单发放同步，系统将面单号分配给网点、业务员或客户。<br>
                        此界面可查看各面单号绑定的快件
                    </div>
                </div>

            </div>
        </fieldset>

        <fieldset class="table-search-fieldset">
            <legend>搜索信息</legend>
            <div style="margin: 10px 10px 10px 10px">
                <form class="layui-form layui-form-pane" action="">

                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">发放日期</label>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="text" name="startDate" id="startDate" placeholder="起始日期" autocomplete="off" class="layui-input">
                            </div>
                            <div class="layui-form-mid">-</div>
                            <div class="layui-input-inline" style="width: 100px;">
                                <input type="text" name="endDate" id="endDate" placeholder="结束日期" autocomplete="off" class="layui-input">
                            </div>
                        </div>

                        <div class="layui-inline">
                            <label class="layui-form-label">发放网点</label>
                            <div class="layui-input-inline">
                                <input type="text" name="baseNet" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline">
                            <button type="submit" class="layui-btn layui-btn-primary"  lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </form>
            </div>
        </fieldset>

        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add"> 添加 </button>
                <button class="layui-btn layui-btn-sm layui-btn-danger data-delete-btn" lay-event="delete"> 删除 </button>
            </div>
        </script>

        <table class="layui-hide" id="expressGrantTableId" lay-filter="employeeTableFilter"></table>

        <script type="text/html" id="currentTableBar">
            <a class="layui-btn layui-btn-normal layui-btn-sm data-count-edit" lay-event="edit">查看面单具体信息</a>
        </script>

    </div>
</div>
<script src="/static/admin/lib/layui-v2.5.5/layui.js" charset="utf-8"></script>
<script>
    layui.use(['form', 'table','laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table;
        var laydate = layui.laydate;

        //日期渲染
        //执行一个laydate实例
        var startDate = laydate.render({
            elem: '#startDate',
            type: 'date',//设置日期的类型
            theme: '#2c78da',
            done: function (value, date) {
                if (value != "") {
                    date.month = date.month - 1;
                    endDate.config.min = date;
                } else {
                    endDate.config.min = startDate.config.min;
                }
            },
        });
        //执行一个laydate实例
        var endDate = laydate.render({
            elem: '#endDate',
            type: 'date',//设置日期的类型
            theme: '#2c78da',
            done: function (value, date) {
                if (value != "") {
                    date.month = date.month - 1;
                    startDate.config.max = date;
                } else {
                    startDate.config.max = endDate.config.max;
                }
            }

        });

        table.render({
            elem: '#expressGrantTableId',
            url: '/admin/expressSheet/queryExpressGrant',
            toolbar: '#toolbarDemo',
            defaultToolbar: [],
            cols: [
                [
                {type: "checkbox",fixed: 'left'},
                {field: 'expressGrantId', width:50,title: 'ID', sort: true,fixed: 'left'},
                {field: 'expressGrantDate',width:150,title: '发放时间',fixed: 'left'},
                {field: 'expressGrantStartNum',width:150,title: '起始单号',fixed: 'left'},
                {field: 'expressGrantEndNum',width:150, title: '结束单号',fixed: 'left'},
                {field: 'sign',width:150, title: '发放类型',templet:function (res) {
                    var type = "";
                    if (res.grantType == 0){
                        type = "网点";
                    }else if(res.grantType == 1){
                        type = "业务员";
                    }else{
                        type = "客户";
                    }

                    return '<span style="color: green;">'+type+'</span>';

                    }},
                {field: 'siteId', hide:true},
                {field: 'siteName',width:150,title: '网点'},
                {field:'employeeId',hide:true},
                {title: '取号者',width:125,templet:function (res) {

                        var html = '<img src="'+res.faceImage+'" width="50" height="50" style="border-radius:100%; "/>'+res.employeeName;
                        return html;


                    }},
                {field:'grantFormat',width:120,title:'发放格式'},
                {field:'grantCount',width:120,title:'发放数量'},
                {field:'yuse',width:140,title:'已使用面单数'},
                {field:'noUse',width:140,title:'未使用面单数'},
                {field:'remark',width:140,title:'备注'},
                {title: '操作', width:150,toolbar: '#currentTableBar', align: "center",fixed: 'right'}
            ]
            ],
            limits: [10, 15, 20, 25, 50, 100],
            limit: 15,
            page: true,
            skin: 'line'
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = data.field;

            //执行搜索重载
            table.reload('expressGrantTableId', {
                where: {

                    startDate:result.startDate,
                    endDate:result.endDate,
                    siteName:result.siteName
                },
                url:'/admin/expressSheet/queryExpressGrantByGrantDateOrSiteName'

            });

            return false;
        });

        /**
         * toolbar监听事件
         */
        table.on('toolbar(employeeTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '添加用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/add.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            } else if (obj.event === 'delete') {  // 监听删除操作
                var checkStatus = table.checkStatus('expressGrantTableId')
                    , data = checkStatus.data;
                layer.alert(JSON.stringify(data));
            }
        });

        //监听表格复选框选择
        table.on('checkbox(employeeTableFilter)', function (obj) {
            console.log(obj)
        });

        table.on('tool(employeeTableFilter)', function (obj) {
            var data = obj.data;

            console.log(data)

            if (obj.event === 'edit') {

                var index = layer.open({
                    title: '编辑用户',
                    type: 2,
                    shade: 0.2,
                    maxmin:true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: '../page/table/edit.html',
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
                return false;
            } else if (obj.event === 'delete') {
                layer.confirm('真的删除行么', function (index) {
                    obj.del();
                    layer.close(index);
                });
            }
        });

    });
</script>

</body>
</html>
